<template>
	<el-container>
		<el-header>
			<el-form
				inline
				label-width="49px"
				:model="queryList"
				style="margin-top: 5px; width: 100%"
			>
				<el-input
					v-model="queryList.Name"
					placeholder="请输入组名称"
					style="width: 150px"
				></el-input>
				&nbsp;
				<el-select
					v-model="queryList.OperType"
					placeholder="请选择操作状态"
					clearable
					:teleported="false"
					style="width: 150px"
				>
					<el-option
						v-for="item in optionsOperType"
						:key="item.value"
						:label="item.label"
						:value="item.value"
					/>
				</el-select>
				&nbsp;
				<el-button type="primary" @click="$refs.mytable.getData()"
					>查询</el-button
				>
			</el-form>
		</el-header>
		<el-container>
			<el-aside width="40%">
				<el-container>
					<el-main class="nopadding">
						<scTable
							ref="mytable"
							:data="listData"
							:attrList="attrList"
							:valueList="valueList"
							:queryList="queryList"
							:sort-orders="['ascending', 'descending']"
							@row-click="rowClick"
							:hideDo="true"
							height="560px"
							style="max-height: 560px; min-width: 560"
						>
							<el-table-column
								label="编码"
								prop="Code"
								width="100"
							></el-table-column>
							<el-table-column
								label="名称"
								prop="Name"
								width="150"
							></el-table-column>
							<el-table-column
								label="操作类型"
								prop="OperTypeName"
								width="100"
								sortable
							>
							</el-table-column>
							<el-table-column
								label="最大数量"
								prop="MaxQty"
								width="100"
								sortable
							></el-table-column>
						</scTable>
					</el-main>
				</el-container>
			</el-aside>
			<el-container>
				<el-main class="nopadding">
					<scTable
						ref="sontable"
						row-key="id"
						stripe
						height="470px"
						:data="selectionRows"
						:hideDo="true"
						:hidePagination="true"
						style="max-height: 470px; min-width: 560"
						@selection-change="handleSelectionChange"
					>
						<el-table-column
							type="selection"
							width="50"
						></el-table-column>
						<el-table-column
							label="商品编码"
							prop="GoodsCode"
							width="120"
						></el-table-column>

						<el-table-column
							label="商品名称"
							prop="GoodsName"
							width="180"
						></el-table-column>
						<el-table-column
							label="单位"
							prop="UomName"
							width="100"
						></el-table-column>
						<el-table-column
							label="默认项"
							prop="IsDefault"
							width="100"
						></el-table-column>
						<el-table-column
							label="默认数量"
							prop="DefaultQty"
							width="120"
						></el-table-column>
					</scTable>
				</el-main>
			</el-container>
		</el-container>
	</el-container>
</template>

<script>
import publicjs from "@/api/model/publicjs";
export default {
	name: "listSon",
	data() {
		return {
			selectionRows: [],
			pkList: ["Code"],
			attrList: {
				Name: "GoodsGroup",
				UseDistinct: false,
				OrgCode: "",
				UseBackUp: false,
				UseGroup: false,
			},
			valueList: {
				Code: "Code",
				Name: "Name",
				OperType: "OperType",
				MaxQty: "MaxQty",
			},
			queryList: {
				Name: "",
				OrgCode: "",
				OperTypeCode: "",
			},
			result: "", // 运行结果
			props1: {
				checkStrictly: true,
				emitPath: false,
			},
			optionsOperType: [],
			multipleSelection: [],
			choiceGroup: {
				groupCode: "",
				groupName: "",
			},
			selectOperType: "",
			selectMaxQty: 0,
		};
	},
	methods: {
		async opBindData() {
			this.$refs.mytable.clearSort();
			this.$refs.mytable.getData();
		},

		async initOptions() {
			var head = new publicjs.head();
			publicjs.initHead(head, "getfirstdatasource");
			var ed = new publicjs.entitydata(head);
			var eo = new publicjs.entityobj();
			eo.AttrList = {
				Name: "GoodsGroup",
				AcceptControl: "OperType",
				OrgCode: "",
			};
			ed.Data.Content.ObjectList.Object.push(eo);
			try {
				var returnValueStr = await this.$API.auth.objProcess.post(ed);
				var returnValue = JSON.parse(returnValueStr);
				// eslint-disable-next-line no-debugger
				//debugger;
				console.log(returnValue.content);
				if (returnValue.Result.OpFlag == "1") {
					var objectList =
						returnValue.Result.Content.ObjectList.Object;
					this.optionsOperType = objectList.rows.row;
				}
			} catch (error) {
				this.loading = false;
				this.$alert(error.message, "提示", { type: "error" });
				return false;
			}
		},
		async rowClick(row) {
			// eslint-disable-next-line no-debugger
			//debugger;
			let groupCode = row.Code;
			this.choiceGroup.groupCode = row.Code;
			this.choiceGroup.groupName = row.Name;
			this.selectOperType = row.OperType;
			this.selectMaxQty = row.MaxQty;
			var head = new publicjs.head();
			//publicjs.initHead(head, "query");
			publicjs.initHead(head, "query");
			var ed = new publicjs.entitydata(head);
			var eo = new publicjs.entityobj();
			eo.AttrList = {
				Name: "GoodsGroupDetail",
				OrgCode: "",
			};
			eo.ValueList = {
				GoodsCode: "",
				GoodsName: "",
				UomCode: "",
				UomName: "",
				IsDefault: "",
				DefaultQty: "",
			};
			eo.QueryList = { GroupCode: groupCode };
			ed.Data.Content.ObjectList.Object.push(eo);
			try {
				var returnValueStr = await this.$API.auth.objProcess.post(ed);
				var returnValue = JSON.parse(returnValueStr);
				if (returnValue) {
					if (returnValue.Result.OpFlag == "0") {
						this.$message.error(
							"操作失败:" + returnValue.Result.OpMsg
						);
						return false;
					} else {
						if (
							returnValue.Result.Content.ObjectList.Object
								.AllCount != "0"
						)
							this.selectionRows =
								returnValue.Result.Content.ObjectList.Object.Rows.Row;
						else this.selectionRows = [];
					}
				}
			} catch (error) {
				this.loading = false;
				this.$message.error("操作失败:" + error);
				//this.emptyText = error.statusText;
				return false;
			}
		},
		handleSelectionChange(val) {
			// console.log(val)
			val["OperType"] = this.selectOperType;
			val["MaxQty"] = this.selectMaxQty;
			this.multipleSelection = val;
		},
	},
	async mounted() {
		await this.initOptions();
		await this.$refs.mytable.getData();
	},
};
</script>

<style></style>
